//
//  UserManager.m
//  CBT
//
//  Created by Mr.Zhang on 2018/12/3.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "UserManager.h"
#import <AFHTTPSessionManager.h>

@implementation UserManager

+(void)changeUserNameWithUserId:(NSString *)userID nickName:(NSString *)nickName block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:nickName forKey:@"nickName"];
    [NetWork requestWithURL:Network_Set_NickName params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)investListWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:page forKey:@"page"];
    [param setObject:@"20" forKey:@"row"];
    [NetWork requestWithURL:Network_GetInvestList params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getUserDoRechargeWithUserId:(NSString *)userID coinId:(NSString *)coinId block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:coinId forKey:@"coinId"];
    [NetWork requestWithURL:Network_DoRecharge params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)drawCapitalOrIncomeWithUserId:(NSString *)userID investId:(NSString *)investId block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"1" forKey:@"type"];
    [param setObject:investId forKey:@"investId"];
    [NetWork requestWithURL:Network_DrawCapitalOrIncome params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvestStateWithUserId:(NSString *)userID investId:(NSString *)investId block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:investId forKey:@"investId"];
    [NetWork requestWithURL:Network_GetInvestState params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}


+(void)getUserContinueInvestWithInvestId:(NSString *)investId block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:investId forKey:@"investId"];
    [NetWork requestWithURL:Network_ContinueInvest params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)userDoInvestWithUserId:(NSString *)userID coinId:(NSString *)coinId value:(NSString *)value day:(NSString *)day block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:coinId forKey:@"coinId"];
    [param setObject:value forKey:@"value"];
    [param setObject:day forKey:@"day"];
    [NetWork requestWithURL:Network_DoInvest params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)userdrawMoneyByAlipayWithUserId:(NSString *)userID walleatAdress:(NSString *)walleatAdress value:(NSString *)value block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:walleatAdress forKey:@"walleatAdress"];
    [param setObject:value forKey:@"value"];
    [NetWork requestWithURL:Network_DrawMoney params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}


+(void)getAssetMsgWithUserId:(NSString *)userID block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [NetWork requestWithURL:Network_GetUserAsset params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvestRecordWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetInvestRecord params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 昨日收益
+(void)getYestodayInvestRecordWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetTodayInvestRecord params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 已完成订单列表
+(void)getUserOrderRecordWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetUserOrder params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 地址列表
+(void)getAddressRecordWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [NetWork requestWithURL:Network_GetUserAddress params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 新增地址
+ (void)addUserAddressWithUserId:(NSString *)userID paras:(NSDictionary *)param block:(manager_result_block)block {

    [NetWork requestWithURL:Network_AddAddress params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 修改地址
+ (void)updateUserAddressWithUserId:(NSString *)userID params:(NSDictionary *)param block:(manager_result_block)block {
    
    [NetWork requestWithURL:Network_UpdateAddress params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// 购买 addUserOrder
+ (void)userDoPCChangeWithUserInfo:(NSDictionary *)param block:(manager_result_block)block {
    [NetWork requestWithURL:Network_AddUserOrder params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getRechargeRecordWithUserId:(NSString *)userID coinId:(NSString *)coinId page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:coinId forKey:@"coinId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetRechargeRecord params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getDrawRecordListWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetDrawRecord params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)setUserIDcardWithUserId:(NSString *)userID type:(NSString *)type image:(UIImage *)image block:(manager_result_block)block
{
    NSDictionary *parameters = @{@"userId":userID,
                                 @"type" : type};
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer.timeoutInterval = 30;
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"multipart/form-data", @"application/json", @"text/html", @"image/jpeg", @"image/png", @"application/octet-stream", @"text/json", nil];
    if ([HEFANTV_DEVICETOKEN length] > 0)
    {
        [manager.requestSerializer setValue:[NSString stringWithFormat:@"%@_%@",[CBTLocalUserManager sharedInstance].userId,HEFANTV_DEVICETOKEN] forHTTPHeaderField:@"authorization"];
    }
    //在请求头中添加当前语言
    [manager.requestSerializer setValue:[kLanguageManager isSimplified] ? @"language_zh" : @"language_en" forHTTPHeaderField:@"language"];
    [manager POST:[NSString stringWithFormat:@"%@%@",kBaseURL_STATIC,@"/cbt/setUserIDcard"] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        NSData *imageData = UIImageJPEGRepresentation(image, 1);
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        // 设置时间格式
        [formatter setDateFormat:@"yyyyMMddHHmmss"];
        NSString *dateString = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString  stringWithFormat:@"%@.jpg", dateString];
        [formData appendPartWithFileData:imageData name:@"picture" fileName:fileName mimeType:@"image/jpeg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        block(responseObject,[responseObject[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,responseObject[@"message"]);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)task.response;
        if (urlResponse.statusCode == 403 || urlResponse.statusCode == 401) {
            [HFStatusView showFailureMessage:kLocalizedString(@"您的登录已失效，请重新登录!",nil)];
            [[NSUserDefaults standardUserDefaults]setObject:@"" forKey:HEFANTV_TOKEN];
            [[NSUserDefaults standardUserDefaults]synchronize];
            [[CBTLocalUserManager sharedInstance]removeUserInfo];
            [((AppDelegate*)[UIApplication sharedApplication].delegate) changeRootVC];
        }else{
            block(nil,kHttpRequestResultError ,kLocalizedString(@"上传失败", nil));
        }
    }];
}

+(void)checkIDcardWithUserId:(NSString *)userID block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [NetWork requestWithURL:Network_CheckIDcard params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvestRatioWithCoinId:(NSString *)coinId block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:coinId forKey:@"userId"];
    [NetWork requestWithURL:Network_GetInvestRatio params:param httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getUserDrawRateWithBlock:(manager_result_block)block
{
    [NetWork requestWithURL:Network_DrawRate params:nil httpMethod:@"GET" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getUserSignInByuserIdWithBlock:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:[CBTLocalUserManager sharedInstance].userId forKey:@"userId"];
    [NetWork requestWithURL:Network_SignInByuserId params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)checkIDcardStatusWithBlock:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:[CBTLocalUserManager sharedInstance].userId forKey:@"userId"];
    [NetWork requestWithURL:Network_GetSignInFlag params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getRewardRate:(manager_result_block)block
{
    [NetWork requestWithURL:Network_GetRewardRate params:nil httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100  && result != nil ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getRewardRecordWithUserId:(NSString *)userID page:(NSString *)page block:(manager_result_block)block
{
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetRewardRecord params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        RewardRecordModel *model = [RewardRecordModel mj_objectWithKeyValues:result[@"data"]];
        block(model,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getUserFeedBackWithContent:(NSString *)content wxId:(NSString *)wxId phone:(NSString *)phone block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:content forKey:@"content"];
    [param setObject:wxId forKey:@"wxId"];
    [param setObject:phone forKey:@"phone"];
    [NetWork requestWithURL:Network_GetUserFeedBack params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 && [[result[@"data"]objectForKey:@"result"]boolValue] == YES ? kHttpRequestResultNormal : kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvitedIncomeWithUserId:(NSString *)userId page:(NSString *)page block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetInvitedIncome params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        InvitationRevenueModel *model = [InvitationRevenueModel mj_objectWithKeyValues:result[@"data"]];
        block(model,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvestDetailsWithUserId:(NSString *)userId page:(NSString *)page block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetInvestDetails params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        InvestDetailsModel *model = [InvestDetailsModel mj_objectWithKeyValues:result[@"data"]];
        block(model,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)getInvitedDetailsWithUserId:(NSString *)userId page:(NSString *)page block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId forKey:@"userId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetInvitedDetails params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        InvitedDetailsModel *model = [InvitedDetailsModel mj_objectWithKeyValues:result[@"data"]];
        block(model,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+ (void)getMinerRateWithCoinId:(NSString *)coinId  block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:coinId forKey:@"coinId"];
    [NetWork requestWithURL:Network_GetMinerRate params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        NSString *slow = @"";
        NSString *fast = @"";
        NSString *defaultValue = @"";
        
        for (NSDictionary *dic in result[@"data"]) {
            if ([dic[@"status"]intValue] == 1) {
                slow = [NSString stringWithFormat:@"%@",dic[@"ratio"]];
            }else if ([dic[@"status"]intValue] == 2) {
                defaultValue = [NSString stringWithFormat:@"%@",dic[@"ratio"]];
            }else if ([dic[@"status"]intValue] == 3) {
                fast = [NSString stringWithFormat:@"%@",dic[@"ratio"]];
            }
        }
        
        NSDictionary *dic = @{@"slow":slow,@"fast":fast,@"defaultValue":defaultValue};
        
        block(dic,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+ (void)checkPayPassWordWithUserID:(NSString *)userID  passWord:(NSString *)passWord block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userID forKey:@"userId"];
    [param setObject:passWord forKey:@"payPassWord"];
    [NetWork requestWithURL:Network_CheckPayPassWord params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}


// 兑换
+ (void)doPCExchangeInfo:(NSDictionary *)param  block:(manager_result_block)block {
    NSLog(@"-----%@",Network_UserDrawPCMoney);
    [NetWork requestWithURL:Network_UserDrawPCMoney params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// akb转账
+ (void)userDoChangeWithUserID:(NSString *)userId  coinId:(NSString *)coinId address:(NSString *)address value:(NSString *)value remark:(NSString *)remark feeRatio:(NSString *)feeRatio block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId  forKey:@"userId"];
    [param setObject:coinId  forKey:@"coinId"];
    [param setObject:address forKey:@"address"];
    [param setObject:value   forKey:@"value"];
    [param setObject:remark  forKey:@"remark"];
    [param setObject:feeRatio forKey:@"feeRatio"];
    [NetWork requestWithURL:Network_UserDoChange params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

// pc转账
+ (void)userDoPCChangeWithUserID:(NSString *)userId coinId:(NSString *)coinId address:(NSString *)address value:(NSString *)value remark:(NSString *)remark feeRatio:(NSString *)feeRatio password:(NSString *)password block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId   forKey:@"userId"];
    [param setObject:coinId   forKey:@"coinId"];
    [param setObject:address  forKey:@"address"];
    [param setObject:value    forKey:@"amount"];
    [param setObject:remark   forKey:@"remark"];
    [param setObject:feeRatio forKey:@"feeRatio"];
    [param setObject:password forKey:@"jyPassword"];

    [NetWork requestWithURL:Network_UserDoPCChange params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+ (void)getChangeRecordWithUserID:(NSString *)userId  coinId:(NSString *)coinId page:(NSString *)page block:(manager_result_block)block {
    
    NSMutableDictionary *param = [[NSMutableDictionary alloc]init];
    [param setObject:userId forKey:@"userId"];
    [param setObject:coinId forKey:@"coinId"];
    [param setObject:@"20" forKey:@"row"];
    [param setObject:page forKey:@"page"];
    [NetWork requestWithURL:Network_GetChangeRecord params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}


@end
